package com.Long.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Title:
 * @Description:
 * @Author: guowl
 * @version： 1.0
 * @Date:2021/7/22
 * @Copyright: Copyright(c)2021 RedaFlight.com All Rights Reserved
 */

public class MQConfig {
    /**
     * 交换机名称
     */
    public static final String QL_TOPIC_EXCHANGE="ql_topic_exchange";
    /**
     * 队列名称
     */
    public static final String QL_QUEUE="ql_queue";

    /**
     * 声明交换机
     */
    @Bean("qlTopicExchange")
    public Exchange topicExchange(){

        return ExchangeBuilder.topicExchange(QL_TOPIC_EXCHANGE).durable(true).build();
    }
    /**
     * 声明队列
     */
    @Bean("qlQueue")
    public Queue qlQueue(){
        return QueueBuilder.durable(QL_QUEUE).build();
    }
    /**
     * 绑定交换机和队列
     */
    @Bean("bindQueueExchange")
    public Binding bindQueueExchange(@Qualifier("qlQueue") Queue queue,
                                     @Qualifier("qlTopicExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("ql.#").noargs();
    }

}
